package fast.ranking;

import fast.loader.Enchant;
import fast.loader.Gem;
import fast.loader.Item;
import fast.loader.ItemEquipped;
import fast.loader.Reforge;
import fast.loader.Slot;
import fast.mvc.Model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;

public class ItemCompare<T> {
	
	Model model;
	ItemEquipped curItem;
	ArrayList<T> items;
	Slot slot;
	ArrayList<EP<T>> comparedItems;
	
	public ItemCompare(Model model,ItemEquipped curItem,ArrayList<T> items,Slot slot){
		this.model = model;
		this.curItem = curItem;
		this.items = items;
		this.slot = slot;
		comparedItems = new ArrayList<EP<T>>();
		
		Iterator<T> ie = items.iterator();
		while(ie.hasNext()){
			T item = ie.next();
			double ep = 0;
			if(item instanceof Item){
				ItemEquippedEP iep = model.calcItemEP2((Item) item, slot, curItem);
				ep = iep.getEp();
				((Item) item).setEp(ep);
				((Item) item).setSuggestion(iep);
			}
			else if(item instanceof Gem){
				ep = model.calcGemEP((Gem) item);
				((Gem) item).setEP(ep);
			}
			else if(item instanceof Enchant){
				ep = model.calcEnchantEP((Enchant) item, slot);
				((Enchant) item).setEP(ep);
			}
			else if(item instanceof Reforge){
				ep = model.calcReforgeEP(curItem.getItem(),(Reforge) item);
				((Reforge) item).setEP(ep);
			}
			comparedItems.add(new EP<T>(item, ep));
		}
		Collections.sort(comparedItems);
		
	}
	
	public ArrayList<EP<T>> getComperator(){		
		return comparedItems;
	}
}
